/**-------------------------------------------------------------------------------------------
** Created by:          qinyx
** Last modified Date:  2014-02-28
** Last Version:        V1.00
** Descriptions:        STM32F407嵌入式实验箱
**
**
**-------------------------------------------------------------------------------------------*/
#include "stm32f4xx.h"
#include "DCMotor.h"
#include "delay.h"

/******************************************************************************************
*函数名称：void RelayGpio_Init(void)
*
*入口参数：无
*
*出口参数：无
*
*功能说明：LED初始化
//DCMOTOR_A      PC13           //  反转
//DCMOTOR_B      PE2            //  正转
//DCMOTOR_S      PE4            //  电机测速引脚
*******************************************************************************************/
void DCMotorGpio_Init(void)
{    
    EXTI_InitTypeDef   EXTI_InitStructure;
    GPIO_InitTypeDef   GPIO_InitStructure;
    NVIC_InitTypeDef   NVIC_InitStructure;
    
    //DCMOTOR_A      PC13
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    
    //DCMOTOR_B      PE2
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOE, &GPIO_InitStructure);
    
	//DCMOTOR_S      PE4            //  电机测速引脚
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);               //  使能IO时钟
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);              //  使能SYSCFG时钟

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;                        //  输入
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;                        //  设置上接
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;                           //  IO口为0
    GPIO_Init(GPIOE, &GPIO_InitStructure);                             

    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource4);       //  初始化中断线4

    EXTI_InitStructure.EXTI_Line = EXTI_Line4;                          //  配置中断线为中断线4
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;                 //  配置中断模式
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;             //  配置为下降沿触发
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;                           //  配置中断线使能
    EXTI_Init(&EXTI_InitStructure);                              

    NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn;             
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; 
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
	
    DCMOTOR_A_L;
    DCMOTOR_B_L;
}
